<?php 
class ControllerTotalReward extends AdminController { 
	 
	public function index() { 

		$this->document->setTitle($this->_['heading_title']);
		
		M('setting/setting');
		
		if ($this->request->isPost() && $this->validate()) {
			$this->model_setting_setting->editSetting('reward', $this->request->post);
		
			$this->session->set_flashdata('success', $this->_['text_success']);			
			$this->redirect(UA('extension/total'));
		}
		
   		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_home'],
			'href'      => UA('common/home'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_total'],
			'href'      => UA('extension/total'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['heading_title'],
			'href'      => UA('total/reward'),
      		'separator' => ' :: '
   		);
		
		if ($this->request->isPost()) {
			$this->data['reward_status'] = P('reward_status');
			$this->data['reward_ratio'] = P('reward_ratio');
			$this->data['reward_sort_order'] = P('reward_sort_order');
		} else {
			$this->data['reward_status'] = C('reward_status');
			$this->data['reward_ratio'] = C('reward_ratio');
			$this->data['reward_sort_order'] = C('reward_sort_order');
		}

		$this->display('total/reward.tpl');
	}

	protected function validate() {
		if (!$this->hasMP()) {
			$this->setMessage('error_warning', $this->_['error_permission']);
			return false;
		}
		return true;
	}
}